package rabbitMQ.client;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.GetResponse;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consume2 {

    public static void main(String[] args) throws IOException, TimeoutException {

        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.8.102");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
//
        GetResponse ltTestQueue = channel.basicGet("ltTestQueue", false);
        if (ltTestQueue != null){
            try {
                System.out.println(new String(ltTestQueue.getBody()));
                channel.basicAck(ltTestQueue.getEnvelope().getDeliveryTag(), false);
            } catch (Exception e) {
                channel.basicReject(ltTestQueue.getEnvelope().getDeliveryTag(), false);
            }
        }
        channel.close();
        connection.close();
    }

}
